#include "bindings/bindings_font.h"
#include "helpers/font_helper.h"
#include "helpers/general.h"
#include "helpers/resource.h"

#include <iostream>

namespace ohos_rive {
napi_value FontCppRegisterFallbackFont(napi_env env, napi_callback_info info)
{
    if (!env) {
        LOGE("Invalid N-API environment in RiveCppRegisterFallbackFont");
        return nullptr;
    }

    napi_value result;
    size_t argc = 1;
    napi_value args[1] = {nullptr};
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Failed to parse arguments for RegisterFallbackFont");
        napi_get_boolean(env, false, &result);
        return result;
    }

    bool isArray;
    status = napi_is_array(env, args[0], &isArray);
    if (status != napi_ok || !isArray) {
        LOGE("Argument must be an array");
        napi_get_boolean(env, false, &result);
        return result;
    }

    status = napi_get_boolean(env, FontHelper::RegisterFallbackFont(env, args[0]), &result);
    if (status != napi_ok) {
        LOGE("Failed to create boolean result");
        return nullptr;
    }

    return result;
}

napi_value FontCppResetFontCache(napi_env env, napi_callback_info info)
{
    FontHelper::resetCache();

    napi_value result;
    napi_get_undefined(env, &result);
    return result;
}
} // namespace ohos_rive